﻿using GamFi.Admin.API.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace GamFi.Admin.API.Persistence.Configurations
{
    public class TokenConfiguration : IEntityTypeConfiguration<Token>
    {
        public void Configure(EntityTypeBuilder<Token> builder)
        {
            builder.HasKey(t => t.Id);

            builder.Property(t => t.Name);

            builder.Property(t => t.TokenPrice);
            
            builder.Property(t => t.TokenSymbol);

            builder.Property(t => t.ChainId);

            builder.Property(t => t.TargetedRaise);

            builder.Property(t => t.TotalRaise);

            builder.Property(t => t.TokenSummary);

            builder.Property(t => t.ImageId);

            builder.HasOne(t => t.Image)
                .WithMany()
                .HasForeignKey(t => t.ImageId)
                .OnDelete(DeleteBehavior.SetNull);

            builder.HasMany(t => t.Purchases)
                .WithOne(p => p.Token)
                .HasForeignKey(p => p.TokenId)
                .OnDelete(DeleteBehavior.Cascade);
        }
    }
}
